<?php  session_start();
/**
* @package		Parents@School
* @copyright	                Copyright (C) 2008 Kristof Beckers. All rights reserved.
* @Version		2.0
* @license		GNU/GPL, see LICENSE.php
**/
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Installatie Parents@School</title>
<link rel="stylesheet" href="../css/template_css.css" type="text/css">
</head>
<body>
<?php
//POST gegevens ophalen.
$db_host = $_POST["server"];
$db_name = $_POST["db_name"];
$db_user = $_POST["db_user"];
$db_pass = $_POST["db_passwd"];
$db_prefix = $_POST["db_prefix"];

//Connectie maken met de database
$conn = mysql_connect($db_host, $db_user, $db_pass) or die ('Error connecting to mysql');
mysql_select_db($db_name, $conn);

//Tabel Leerkrachten aanmaken
$db_lk = $db_prefix."leerkracht";
$sqllk = "CREATE TABLE `".$db_lk."` (
  `ID` int(50) NOT NULL auto_increment,
  `LeerkrachtID` varchar(50) NOT NULL default '',
  `Leerkrachtnaam` varchar(50) NOT NULL default '',
  `password` varchar(50) NOT NULL default '',
  `Klas` varchar(50) NOT NULL default 'LK',
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1" ;

mysql_query($sqllk, $conn);

echo " De tabel $db_lk is aangemaakt... <br /><br />";

//Tabel vakken aanmaken.

$db_vak = $db_prefix."vakken";

$sqlvak = "CREATE TABLE `".$db_vak."` (
  `OpdrachtID` int(50) NOT NULL auto_increment,
  `Klas` varchar(50) NOT NULL default '',
  `Vak` varchar(50) NOT NULL default '',
  `LeerkrachtID` varchar(50) NOT NULL default '',
  `Leerkrachtnaam` varchar(50) NOT NULL default '',
  `Klastitularis` varchar(50) NOT NULL default '',
  `Lokaal` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`OpdrachtID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ";

mysql_query($sqlvak, $conn);

echo " De tabel $db_vak is aangemaakt...<br /><br />";

//Tabel Parameters aanmaken.

$db_param = $db_prefix."parameters";

$sqlparam = "CREATE TABLE `".$db_param."` (
  `Beginuur` varchar(50) NOT NULL default '00:00:00',
  `Einduur` varchar(50) NOT NULL default '00:00:00',
  `Sessieduur` varchar(50) NOT NULL default '00:00:00',
  `Klasdirectie` varchar(50) NOT NULL default '',
  `datum` varchar(50) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=utf8";

mysql_query($sqlparam, $conn);

echo " De tabel $db_param is aangemaakt...<br /><br />";

//Tabel reservaties aanmaken.

$db_res = $db_prefix."reservaties";

$sqlres = "CREATE TABLE `".$db_res."` (
  `ReservatieID` int(50) NOT NULL auto_increment,
  `Gebruikersnaam` varchar(50) NOT NULL default '',
  `Klas` varchar(50) NOT NULL default '',
  `LeerkrachtID` varchar(50) NOT NULL default '',
  `Leerkrachtnaam` varchar(50) NOT NULL default '',
  `Uur` varchar(50) NOT NULL default '',
  `Lokaal` varchar(50) NOT NULL default '',
  `Vak` varchar(50) NOT NULL default '',
  `datum` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`ReservatieID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

mysql_query($sqlres, $conn);

echo " De tabel $db_res is aangemaakt...<br /><br />";

//Tabel users aanmaken.

$db_users = $db_prefix."user";

$sqluser = "CREATE TABLE `".$db_users."` (
  `ID` int(50) NOT NULL auto_increment,
  `username` varchar(50) NOT NULL default '',
  `password` varchar(50) NOT NULL default '',
  `klas` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

mysql_query($sqluser, $conn);

echo " De tabel $db_users is aangemaakt... <br /><br />";

//Tabel staff aanmaken.

$db_staff = $db_prefix."staff";

$sqlstaff = "CREATE TABLE `".$db_staff."` (
  `ID` int(50) NOT NULL auto_increment,
  `username` varchar(50) NOT NULL default '',
  `password` varchar(50) NOT NULL default '',
  `admin` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

mysql_query($sqlstaff, $conn);

echo " De tabel $db_staff is aangemaakt... <br /><br />";

//Tabel Date aanmaken.

$db_date = $db_prefix."date";

$sqldate = "CREATE TABLE `".$db_date."` (
  `ID` int(50) NOT NULL auto_increment,
  `date` varchar(50) NOT NULL default '',
   PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

mysql_query($sqldate, $conn);

echo " De tabel $db_date is aangemaakt... <br /><br />";

// Eerste admin gebruiker aanmaken.
$sql_staff_input="INSERT INTO `".$db_staff."` VALUES(1, 'admin', '21232f297a57a5a743894a0e4a801fc3', '1')";

mysql_query($sql_staff_input, $conn);

$File = "../include/config.php";
$Handle = fopen($File, 'w');
$Data = "<?php 
/**
* @package		Parents@School.
* @copyright	Copyright (C) 2008 Kristof Beckers. All rights reserved.
* @Version		1.0
* @license		GNU/GPL, see LICENSE.php
**/\n";
fwrite($Handle, $Data);
$Data = "$";
fwrite($Handle, $Data);
$Data = "dbhost = \"$db_host\"; \n";
fwrite($Handle, $Data);
$Data = "$";
fwrite($Handle, $Data);
$Data = "dbname = \"$db_name\"; \n";
fwrite($Handle, $Data);
$Data = "$";
fwrite($Handle, $Data);
$Data = "dbuser = \"$db_user\"; \n";
fwrite($Handle, $Data);
$Data = "$";
fwrite($Handle, $Data);
$Data = "dbpasswd = \"$db_pass\"; \n";
fwrite($Handle, $Data);
$Data = "$";
fwrite($Handle, $Data);
$Data = "dbprefix = \"$db_prefix\"; \n ";
fwrite($Handle, $Data);
$Data = "$";
fwrite($Handle, $Data);
$Data = "installation = \"1\"; \n ?>";
fwrite($Handle, $Data);
fclose($Handle);



echo "  Configuratie bestand is geschreven <br /><br />

U kan inloggen met gebruikersnaam \" admin \"en wachtwoord \"admin \"<br /><br />

De database is klaar voor gebruik.<br /><br />

U kan <a href='../admin/index.php'>hier</a> inloggen.


";

mysql_close($conn);



?>
</body>
</html>
